package com.sh.suhe.utildemos.views.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.sh.suhe.utildemos.R
import com.sh.suhe.utildemos.SDKManager
import com.sh.suhe.utildemos.model.PDAData
import com.sh.suhe.utildemos.utils.JsonUtil
import com.sh.suhe.utildemos.utils.LogUtil
import com.sh.suhe.utildemos.utils.socket.DataEngine
import com.sh.suhe.utildemos.utils.socket.util.EntityObject
import kotlinx.android.synthetic.main.activity_socket.*
import kotlin.collections.HashMap

class SocketActivity : AppCompatActivity() {
    lateinit var a : DataEngine

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_socket)
        SDKManager.getInstance().context = this
        //初始化socket
        DataEngine.getInstance().init()
    }

    override fun onDestroy() {
        super.onDestroy()
        DataEngine.getInstance().release()
    }

    fun sendData(view: View) {
        var map = HashMap<String,Object>()
        val param:PDAData = PDAData()
        param.id = "111111我都呃呃呃"
        param.name = "22222222"
        re_tv.text="请求中。。。"
        DataEngine.getInstance().request(EntityObject.SEND_SCAN,param) { b: Boolean, entityObject: EntityObject ->
            if (b){
                val str = entityObject.entity as PDAData
                re_tv.text = JsonUtil.object2Json(str)
            }else{
                re_tv.text="请求失败"
            }
            LogUtil.d("SocketActivity","data is show")
         }
    }
}
